package lxmysql

import (
	"github.com/astaxie/beego/orm"
	_ "github.com/go-sql-driver/mysql"
)

const (
	DEFAULT_EXPIRE   = 300 //默认缓存5分钟
	DEFAULT_MAXCOUNT = 100 //默认最大条数
)

type MapMysqlConn struct {
	Name   string
	SqlCon string
}

// InitMysqls 初始化MySQL
func InitMysqls(conns []MapMysqlConn, cachedb string) (err error) {

	LXMYSQLCACHEDB = cachedb

	err = orm.RegisterDriver("mysql", orm.DRMySQL)
	if err != nil {
		return
	}

	for _, v := range conns {
		err = orm.RegisterDataBase(v.Name, "mysql", v.SqlCon)
		if err != nil {
			return
		}
	}

	return
}
